# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html

import json
from HouseData.items import HousedataItem
from .sql import Sql

class HousedataPipeline(object):

    def process_item(self, item, spider):

        if isinstance(item,HousedataItem):
            Id=item['Id']
            Region=item['Region']
            ret = Sql.Select_id(Id,Region)
            if ret[0] == 1:
                print('ID已经存在')

            else:
                Sql.Insert_House(item['Id'],item['Region'],item['Garden'],item['Layout'],item['Size'],item['Direction'],item['Renovation'],item['Elevator'],item['Price'])
                print(item['Region'])
                print('储存数据中')